package rocket.calendar;

import java.util.ArrayList;

/**
 * @author justin
 * @version
 *One full year in a handy bit-based format
 */
public class Year {
	
	private int theYear;
	
	private boolean leap;
	
	private ArrayList<Day> days;
	
	/**
	 * 
	 */
	public Year() {
		this(2011);
	}
	
	/**
	 * @param year
	 */
	public Year(int year) {
		this.theYear = year;
		this.leap = checkLeap(year);
		int numDays = 365;
		if (leap) numDays = 366;
		days = new ArrayList<Day>();
		for (int i = 0; i < numDays; i++){
			days.add(new Day(i));
		}
	}
	
	/**
	 * 
	 * @param year
	 * @return whether or not the year is a leap.
	 */
	public boolean checkLeap(int year){
		return (year % 4 == 0) && (!(year % 100 == 0) || (year % 400 == 0));
	}
	
	/**
	 * @param d
	 * @return days.get(d)
	 */
	public Day getDay(int d){
		return days.get(d);
	}
	
	/**
	 * @return leap
	 */
	public boolean isLeap(){
		return leap;
	}
	
	/**
	 * @return theYear
	 */
	public int theYear(){
		return theYear;
	}
	
	/**
	 * @return days
	 */
	public ArrayList<Day> getYear(){
		return days;
	}

	/**
	 * @return theYear
	 */
	public String toString(){
		return "" + theYear;
	}

}
